Skip to content

The password definition belongs to UsersRepository - #22

Merged
byjg merged 1 commit into
masterfrom
7.0
Oct 29, 2026
Merged

byjg merged 1 commit into
masterfrom
7.0

Conversation

@byjg

@byjg byjg commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Changes

  • UsersRepository::__construct(DatabaseExecutor $executor, string $usersClass, ?PasswordDefinition $passwordDefinition = null): with a definition, it sets the password mapper on it (to tell a hash from a plain password) and installs PasswordDefinitionValidator on its MicroORM Repository, chained to the validator the model declares. Every save checks a plain password, through UsersService, UsersRepository or the MicroORM Repository, even when no UsersService was ever built. New getPasswordDefinition().
  • UsersService no longer takes a PasswordDefinition (it used to install the validator as a side effect of its constructor). It applies the repository's definition to the users it creates or loads.

Breaking change (see CHANGELOG-7.0.md)

Move the definition from new UsersService(..., $loginField, $definition) to new UsersRepository($executor, $class, $definition). A definition still passed to the service is an extra argument PHP ignores. With byjg/config, an injected UsersRepository binding receives a bound PasswordDefinition by type.

Tests

PasswordUpgradeTest::testRepositorySaveChecksTheDefinition builds a UsersRepository with a definition and no UsersService: a weak password is rejected through UsersRepository::save() and Repository::save(). Removing the repository's wiring fails it. The service test of TestUsersBase gives the definition to the repository. PHPUnit 186 tests and Psalm pass.

- UsersRepository takes the PasswordDefinition and sets PasswordDefinitionValidator on its
  MicroORM Repository: every save checks a plain password, also without UsersService
- UsersService no longer takes a PasswordDefinition; it applies the repository's to the users it
  creates or loads
@byjg
byjg merged commit a90f855 into master Oct 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant